# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def rob(self, root: TreeNode) -> int:
        maxMoney, _ = self.robNode(root)
        return maxMoney

    def robNode(self, root: TreeNode):
        if root is None:
            return 0, 0
        left = self.robNode(root.left)
        right = self.robNode(root.right)
        nodeIn = root.val + left[1] + right[1]
        nodeNotIn = left[0] + right[0]
        return max(nodeIn, nodeNotIn), nodeNotIn


if __name__ == '__main__':
    so = Solution()
    nums1 = [1, 2, 2, 1]
    nums2 = [2, 2, 1]
    r = so.intersection(nums1, nums2)
    print(r)
